<!--添加库存单位-->
<template>
    <div class="unit-add-root">
        <el-dialog
                title="添加库存单位"
                :visible.sync="dialogVisible"
                width="40%"
                :close="close"
                :before-close="close">

            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="单位名称">
                    <el-input v-model="form.unit"></el-input>
                </el-form-item>
                <el-form-item label="单位数量">
                    <el-input v-model="form.count"></el-input>
                </el-form-item>
                <el-form-item label="默认">
                    <el-select v-model="form.isDefault">
                        <el-option v-for="(item, i) in default__" :key="i" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="close">取 消</el-button>
                <el-button type="primary" @click="stockUnitAdd">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import API from '@/api/api';
export default {
    name: "StockUnitAdd",
    data() {
        return {
            // 对话框标志位
            dialogVisible: true,
            form: {
                isDefault: 0,
            },

            default__: [
                {label: '是', value: 1},
                {label: '否', value: 0}
            ]
        }
    },
    methods: {
        close() {
            this.$emit('close');
        },
        stockUnitAdd() {
          let url = API.unit.add;
          let param = JSON.parse(JSON.stringify(this.form));
          this.$post(url, param).then(res => {
              let data = res.data;
              if (data.success) {
                  this.$message.success({
                      showClose: true,
                      message: data.msg
                  });
                  this.close();
              } else {
                  this.$message.error({
                      showClose: true,
                      message: data.msg
                  })
              }
          }).catch( err => {
              this.$message.closeAll();
              this.$message.error({
                  showClose: true,
                  message: "请求失败!"
              })
          })
        },
    }
}
</script>

<style scoped>

</style>
